/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Controller.Imprimante;
import Controller.Materiel;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ImprimanteDAO extends AbstractDAO<Imprimante> {

    private MaterielDAO matDAO;

    public ImprimanteDAO(Connection connect) {
        super(connect);
        this.matDAO = new MaterielDAO(connect);
    }

	/**
	 * Insertion d'une imprimante
	 * @param obj
	 * @return true/false
	 */
    @Override
    public boolean insert(Imprimante obj) {
        try {
            Materiel mat = new Materiel();
            mat.setNumCB(obj.getNumCB());
            mat.setNumCompta(obj.getNumCompta());
            mat.setNumSerie(obj.getNumSerie());
            mat.setNom(obj.getNom());
            mat.setDescriptif(obj.getDescriptif());
            mat.setDateHT(obj.getDateHT());
            mat.setPrixHT(obj.getPrixHT());
            mat.setGarantie(obj.getGarantie());
            mat.setNumBC(obj.getNumBC());
            mat.setBudget(obj.getBudget());
            mat.setAmortissement(obj.getAmortissement());
            mat.setType(obj.getType());
            mat.setFournisseur(obj.getFournisseur());
            mat.setMarque(obj.getMarque());
            mat.setSalle(obj.getSalle());
            mat.setSecteur(obj.getSecteur());
            
            this.matDAO.insert(mat);
            
            String query = "INSERT INTO imprimante(numCB,refCC,refCN,pUSB,pParall,pRes,TYPEI,A3,A4)"
                    + " VALUES (" + obj.getNumCB() + ",'" + obj.getRefCC()+ "','" + obj.getRefCN() + "','" + obj.getpUSB() + "','" 
                    + obj.getpParall() + "','" + obj.getpRes() + "','" + obj.getTYPEI() + "','" + obj.getA3() + "','" + obj.getA4()+ "');";
            System.out.println(query);
            
            this.connect.createStatement().executeUpdate(query);

            return true;
            
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    protected boolean update(Imprimante obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected boolean delete(Imprimante obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected Imprimante findById(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
